/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.gulangyu.manage.mvc;

import com.mycompany.yourtrade.common.DerongVariables;
import com.mycompany.yourtrade.common.RedisService;
import com.mycompany.yourtrade.common.SmsClient;
import com.mycompany.yourtrade.common.UpYunService;
import com.mycompany.yourtrade.model.AjaxData;
import com.mycompany.yourtrade.model.Commodity;
import com.mycompany.yourtrade.model.Shop;
import com.mycompany.yourtrade.service.manage.ShopManageService;
import com.mycompany.yourtrade.service.user.UserService;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author superxg
 */
@Controller
@RequestMapping("/commodity")
public class CommodityManageController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private UpYunService UpYunService;
    @Autowired
    private UserService userService;
    @Autowired
    private ShopManageService shopManageService;
    @Autowired
    private SmsClient smaClient;
    @Autowired
    private RedisService redisService;
    @Autowired
    private DerongVariables derongVariables;
    
    //商品管理列表
    @RequestMapping(value = "comlist", method = RequestMethod.GET)
    public ModelAndView comlist(HttpServletRequest request) {
        ModelAndView mv = new ModelAndView("commodity/list");
        //String sellerId = SessionUtils.getSellerId(request);
        Shop shop = shopManageService.getShopBySellerId("4a954fb2-223b-4945-bd82-83e3de8c16c9");
        //List<Commodity> lc = shopManageService.getCommodityByShopId(shop.getId());
//        shop.setIdImageUrl(derongVariables.getDomain() + shop.getIdImageUrl());
//        shop.setLicenseUrl(derongVariables.getDomain() + shop.getLicenseUrl());
        mv.addObject("shop", shop);
        return mv;
    }
    /**
     * 获取商品列表数据
     *
     * @param draw
     * @param start
     * @param length
     * @param loginNameQuery
     * @return
     */
    @RequestMapping(value = "getComList", method = RequestMethod.GET)
    public @ResponseBody AjaxData<Commodity> getComList(HttpServletRequest request ,
            HttpServletResponse response ,
            @RequestParam(value = "draw",required = false) Integer draw,
            @RequestParam(value = "start",required = false) Integer start,
            @RequestParam(value = "length",required = false) Integer length,
            @RequestParam(value = "cNameQuery",required = false) String cNameQuery) throws IOException {
        Shop shop = shopManageService.getShopBySellerId("4a954fb2-223b-4945-bd82-83e3de8c16c9");
        List<Commodity> lc = shopManageService.getCommodityByShopId(shop.getId(),start,length);
        Integer n = shopManageService.getCountByShopId(shop.getId());
        AjaxData<Commodity> data = new AjaxData(draw,
                n,
                n,
                lc);
          return data;
    }
}
